import java.util.Scanner;

public class day230421 {
    // 有jia币
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            if (n == 1) {
                System.out.println(0);
                continue;
            }
            if (n == 2 || n == 3) {
                System.out.println(1);
                continue;
            }
            int i = 1;
            while (n > 3) {
                if (n % 3 == 0) {
                    n /= 3;
                } else {
                    n /= 3;
                    n++;
                }
                i++;
            }
            System.out.println(i);
        }
    }

    // 求正数数组的最小不可组成和
    public static int getFirstUnFormedNum(int[] arr) {
        int min = arr[0];
        int max = 0;
        for (int i = 0; i < arr.length; i++) {
            max += arr[i];
            if (min > arr[i]) {
                min = arr[i];
            }
        }
        int[][] dp = new int[arr.length + 1][max + 1];
        for (int i = 1; i < dp.length; i++) {
            for (int j = 1; j < dp[0].length; j++) {
                int a = arr[i - 1];
                if (a > j) {
                    // 这个数太大了, 比当前正数还大
                    dp[i][j] = dp[i - 1][j];
                } else {
                    dp[i][j] = Math.max(dp[i - 1][j],
                            dp[i - 1][j - a] + a);
                }
            }
        }
        for (int i = min; i <= max; i++) {
            if (i != dp[arr.length][i]) {
                return i;
            }
        }
        return max + 1;
    }

    public static void main(String[] args) {
        int[] arr = {3, 2 ,4};
        System.out.println(getFirstUnFormedNum(arr));
    }

    // 背包问题
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int v = in.nextInt();
        int[] c = new int[n];
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = in.nextInt();
            w[i] = in.nextInt();
        }
        int[][] dp = new int[n + 1][v + 1];
        for (int i = 1; i <= n; i ++) {
            for (int j = 1; j <= v; j++) {
                if (w[i - 1] > j) {
                    // 重量太大, 放不下
                    dp[i][j] = dp[i - 1][j];
                } else {
                    // 放
                    int a = dp[i - 1][j - w[i - 1]] + c[i - 1];
                    // 不放
                    int b = dp[i - 1][j];
                    dp[i][j] = Math.max(a, b);
                }
            }
        }
        System.out.println(dp[n][v]);
    }
}
